package com.xbongbong.pro.enums.raiders.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 价值攻略发布枚举
 * @author zcp
 * @version v1.0
 * @date 19/9/19 019 11:23
 * @update 19/9/19 019 11:23
 * @since v1.0
 */
@Getter
public enum RaidersPublishEnum {
    /**
     * 发布枚举，对应数据库内publish字段
     */
    /**
     * 下架后才能变为待发布
     */
    UN_PUBLISH(1, "enum.raidersPublish.name.un_publish", "enum.raidersPublish.operate.un_publish"),

    /**
     * 上架后才能变为已发布
     */
    PUBLISH(2, "enum.raidersPublish.name.publish", "enum.raidersPublish.operate.publish"),

    UNKNOWN(404, "enum.raidersPublish.name.unknown", "enum.raidersPublish.operate.unknown"),

            ;

    /**
     * 枚举值 --
     */
    private final int code;
    /**
     * 枚举信息--中文名称
     */
    private final String name;
    /**
     * 枚举信息--操作
     */
    private final String operate;

    RaidersPublishEnum(int code, String name, String operate) {
        this.code = code;
        this.name = name;
        this.operate = operate;
    }

    /**
     * 通过code获取枚举
     * @param code
     * @return com.xbongbong.pro.enums.raiders.enums.RaidersPublishEnum
     * @author zcp
     * @date 19/9/19 019 14:01
     * @update 19/9/19 019 14:01
     * @since v1.0
     * @version v1.0
     */
    public static RaidersPublishEnum getByCode(int code){
        for (RaidersPublishEnum cache : values()) {
            if (Objects.equals(cache.code, code)) {
                return cache;
            }
        }
        return UNKNOWN;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getOperate() {
        return I18nMessageUtil.getMessage(operate);
    }
}
